package com.bootreview.common;

public class S2 {
    public static void main(String[] args) {
        int[] arr = {5, 1, 4, 2, 8};
        System.out.println("排序前的数组：");
        a(arr);
        b(arr);
        System.out.println("排序后的数组：");
        a(arr);
    }
    public static void b(int[] arr) {
        int n = arr.length;
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int t = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = t;
                }
            }
        }
    }
    public static void a(int[] arr) {
        for (int num : arr) {
            System.out.print(num + " ");
        }
        System.out.println("实现冒泡排序功能");

    }
}
